<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.1.1">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/avatar.jpg">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/avatar.jpg">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/avatar.jpg">
  <link rel="mask-icon" href="/images/avatar.jpg" color="#222">
  <meta name="msvalidate.01" content="4AF2328B2035748153A041B7EEF3D15C">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Noto+Serif+SC:300,300italic,400,400italic,700,700italic%7CLobster:300,300italic,400,400italic,700,700italic%7CPingFang+SC:300,300italic,400,400italic,700,700italic%7CRoboto+Mono:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.33/fancybox/fancybox.css" integrity="sha256-gkQVf8UKZgQ0HyuxL/VnacadJ+D2Kox2TCEBuNQg5+w=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"ethanliu6.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":true,"sidebar":{"position":"left","display":"always","padding":12,"offset":18},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":true,"color":"#222","save":"manual"},"mediumzoom":true,"lazyload":true,"pangu":false,"comments":{"style":"buttons","active":"changyan","storage":true,"lazyload":false,"nav":null,"activeClass":"changyan"},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":6,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="JavaSE进阶——Day01 该篇主要讲解Java中的继承、抽象类">
<meta property="og:type" content="article">
<meta property="og:title" content="JavaSE进阶——Day01 继承、抽象类">
<meta property="og:url" content="http://ethanliu6.github.io/2024/03/25/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day01/day01_JavaSE%E8%BF%9B%E9%98%B6-%E7%BB%A7%E6%89%BF,%E6%8A%BD%E8%B1%A1%E7%B1%BB/index.html">
<meta property="og:site_name" content="&lt;font color&#x3D;&#39;white&#39; &gt;Ethan の Blog&lt;&#x2F;font&gt;">
<meta property="og:description" content="JavaSE进阶——Day01 该篇主要讲解Java中的继承、抽象类">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-03-24T16:00:00.000Z">
<meta property="article:modified_time" content="2024-04-20T15:13:51.474Z">
<meta property="article:author" content="Ethan Liu">
<meta property="article:tag" content="Java">
<meta property="article:tag" content="Java进阶">
<meta name="twitter:card" content="summary">


<link rel="canonical" href="http://ethanliu6.github.io/2024/03/25/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day01/day01_JavaSE%E8%BF%9B%E9%98%B6-%E7%BB%A7%E6%89%BF,%E6%8A%BD%E8%B1%A1%E7%B1%BB/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"http://ethanliu6.github.io/2024/03/25/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day01/day01_JavaSE%E8%BF%9B%E9%98%B6-%E7%BB%A7%E6%89%BF,%E6%8A%BD%E8%B1%A1%E7%B1%BB/","path":"2024/03/25/JavaNotes/JavaSE进阶/day01/day01_JavaSE进阶-继承,抽象类/","title":"JavaSE进阶——Day01 继承、抽象类"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>JavaSE进阶——Day01 继承、抽象类 | <font color='white' >Ethan の Blog</font></title>
  








  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<style>.darkmode--activated{--body-bg-color:#282828;--content-bg-color:#333;--card-bg-color:#555;--text-color:#ccc;--blockquote-color:#bbb;--link-color:#ccc;--link-hover-color:#eee;--brand-color:#ddd;--brand-hover-color:#ddd;--table-row-odd-bg-color:#282828;--table-row-hover-bg-color:#363636;--menu-item-bg-color:#555;--btn-default-bg:#222;--btn-default-color:#ccc;--btn-default-border-color:#555;--btn-default-hover-bg:#666;--btn-default-hover-color:#ccc;--btn-default-hover-border-color:#666;--highlight-background:#282b2e;--highlight-foreground:#a9b7c6;--highlight-gutter-background:#34393d;--highlight-gutter-foreground:#9ca9b6}.darkmode--activated img{opacity:.75}.darkmode--activated img:hover{opacity:.9}.darkmode--activated code{color:#69dbdc;background:0 0}button.darkmode-toggle{z-index:9999}.darkmode-ignore,img{display:flex!important}.beian img{display:inline-block!important}</style></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title"><font color='white' >Ethan の Blog</font></p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description"><font color='#FDABC1' size=3>清醒的停留，胜过——盲目的前行</font></p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-关于我"><a href="/aboutme/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">18</span></a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">14</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">53</span></a></li><li class="menu-item menu-item-love"><a href="/categories/Love/" rel="section"><i class="fas fa-heart fa-fw"></i>Love</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BB%A7%E6%89%BF"><span class="nav-text">1继承</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E5%AD%A6%E4%B9%A0%E7%BB%A7%E6%89%BF"><span class="nav-text">1.1 为什么要学习继承 ?</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BB%A7%E6%89%BF%E8%83%BD%E8%A7%A3%E5%86%B3%E4%BB%80%E4%B9%88%E9%97%AE%E9%A2%98"><span class="nav-text">1.2 继承能解决什么问题 ?</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E7%BB%A7%E6%89%BF%E4%B8%AD%E6%88%90%E5%91%98%E8%AE%BF%E9%97%AE%E7%9A%84%E7%89%B9%E7%82%B9"><span class="nav-text">1.3 继承中成员访问的特点 ?</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%96%B9%E6%B3%95%E9%87%8D%E5%86%99%E4%B8%8E%E6%96%B9%E6%B3%95%E9%87%8D%E8%BD%BD%E5%8C%BA%E5%88%AB%E5%9C%A8%E4%BA%8E%E5%93%AA%E9%87%8C"><span class="nav-text">1.4
方法重写与方法重载区别在于哪里 ?</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%8A%BD%E8%B1%A1%E7%B1%BB"><span class="nav-text">2. 抽象类</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%8A%BD%E8%B1%A1%E7%B1%BB%E5%AD%98%E5%9C%A8%E7%9A%84%E6%84%8F%E4%B9%89"><span class="nav-text">2.1 抽象类存在的意义 ?</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%8A%BD%E8%B1%A1%E7%B1%BB%E4%BD%BF%E7%94%A8%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9"><span class="nav-text">2.2 抽象类使用注意事项 ?</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E9%9A%BE%E7%82%B9"><span class="nav-text">3. 设计模式(难点)</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F-%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E6%9C%89%E4%BB%80%E4%B9%88%E4%BC%98%E5%8A%BF"><span class="nav-text">3.1 什么是设计模式 ,
设计模式有什么优势 ?</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%A8%A1%E6%9D%BF%E6%96%B9%E6%B3%95%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F%E7%9A%84%E4%BD%9C%E7%94%A8-%E4%BD%BF%E7%94%A8%E7%9A%84%E6%96%B9%E5%BC%8F"><span class="nav-text">3.2 模板方法设计模式的作用 ,
使用的方式 ?</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%AC%94%E8%AE%B0"><span class="nav-text">笔记</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BB%A7%E6%89%BF-1"><span class="nav-text">继承</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%97%AE%E9%A2%981%E4%BB%80%E4%B9%88%E6%98%AF%E7%BB%A7%E6%89%BF"><span class="nav-text">问题1：什么是继承</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%97%AE%E9%A2%982%E7%BB%A7%E6%89%BF%E8%A7%A3%E5%86%B3%E7%A8%8B%E5%BA%8F%E4%B8%AD%E7%9A%84%E4%BB%80%E4%B9%88%E9%97%AE%E9%A2%98"><span class="nav-text">问题2：继承解决程序中的什么问题？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%97%AE%E9%A2%983%E7%BB%A7%E6%89%BF%E6%80%8E%E4%B9%88%E4%BD%BF%E7%94%A8-%E5%86%99%E4%BB%A3%E7%A0%81"><span class="nav-text">问题3：继承怎么使用？ &#x2F;&#x2F;写代码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%97%AE%E9%A2%984%E7%BB%A7%E6%89%BF%E5%9C%A8%E4%BD%BF%E7%94%A8%E4%B8%AD%E6%9C%89%E4%BD%BF%E7%94%A8%E6%B3%A8%E6%84%8F%E7%BB%86%E8%8A%82"><span class="nav-text">问题4：继承在使用中有使用注意细节</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%B9%E6%B3%95%E7%9A%84%E4%BD%93%E7%8E%B0"><span class="nav-text">方法的体现：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%87%8D%E8%BD%BD"><span class="nav-text">重载</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%87%8D%E5%86%99"><span class="nav-text">重写</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%96%B9%E6%B3%95%E9%87%8D%E5%86%99"><span class="nav-text">方法重写：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#this%E5%85%B3%E9%94%AE%E5%AD%97%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="nav-text">this关键字的使用：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jvm%E5%86%85%E5%AD%98%E5%88%92%E5%88%86"><span class="nav-text">JVM内存划分：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#this%E5%BD%93%E5%89%8D%E7%B1%BB%E5%AF%B9%E8%B1%A1%E5%BC%95%E7%94%A8"><span class="nav-text">this：当前类对象引用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#super%E7%88%B6%E7%B1%BB%E5%AF%B9%E8%B1%A1%E5%BC%95%E7%94%A8"><span class="nav-text">super：父类对象引用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%99%AE%E9%80%9A%E7%B1%BB"><span class="nav-text">普通类:</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%8A%BD%E8%B1%A1%E7%B1%BB-1"><span class="nav-text">抽象类：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F"><span class="nav-text">什么是设计模式？</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%A8%A1%E6%9D%BF%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F"><span class="nav-text">模板设计模式：</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Ethan Liu"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Ethan Liu</p>
  <div class="site-description" itemprop="description"><font color='#0000FF' size=1.5px>语言学 | NLP | Py | Java</font></div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">53</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL2V0aGFubGl1Ng==" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;ethanliu6"><i class="fab fa-github fa-fw"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOmxpdWUyMzM2QGdtYWlsLmNvbQ==" title="E-Mail → mailto:liue2336@gmail.com"><i class="fa fa-envelope fa-fw"></i>E-Mail</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9zcGFjZS5iaWxpYmlsaS5jb20vMTMyNzA5OTk3Nw==" title="BiliBili → https:&#x2F;&#x2F;space.bilibili.com&#x2F;1327099977"><i class="fa-brands fa-bilibili fa-fw"></i>BiliBili</span>
      </span>
      <span class="links-of-author-item">
        <a href="/categories/Love/" title="Love → &#x2F;categories&#x2F;Love&#x2F;" rel="noopener me"><i class="fa fa-heart fa-fw"></i>Love</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://ethanliu6.github.io/2024/03/25/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day01/day01_JavaSE%E8%BF%9B%E9%98%B6-%E7%BB%A7%E6%89%BF,%E6%8A%BD%E8%B1%A1%E7%B1%BB/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Ethan Liu">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="<font color='white' >Ethan の Blog</font>">
      <meta itemprop="description" content="<font color='#0000FF' size=1.5px>语言学 | NLP | Py | Java</font>">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="JavaSE进阶——Day01 继承、抽象类 | <font color='white' >Ethan の Blog</font>">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          JavaSE进阶——Day01 继承、抽象类<span class="exturl post-edit-link" data-url="aHR0cHM6Ly9naXRodWIuY29tL0V0aGFuTGl1Ni9ldGhhbmxpdTYuZ2l0aHViLmlvL3RyZWUvbWFzdGVyL19wb3N0cy9KYXZhTm90ZXMvSmF2YVNF6L+b6Zi2L2RheTAxL2RheTAxX0phdmFTRei/m+mYti3nu6fmib8s5oq96LGh57G7Lm1k" title="编辑"><i class="fa fa-pen-nib"></i></span>
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2024-03-25 00:00:00" itemprop="dateCreated datePublished" datetime="2024-03-25T00:00:00+08:00">2024-03-25</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2024-04-20 23:13:51" itemprop="dateModified" datetime="2024-04-20T23:13:51+08:00">2024-04-20</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Java%E5%85%A8%E6%A0%88/" itemprop="url" rel="index"><span itemprop="name">Java全栈</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="far fa-comment"></i>
      </span>
      <span class="post-meta-item-text">Changyan：</span>
    
    <a title="JavaSE进阶——Day01 继承、抽象类" href="/2024/03/25/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day01/day01_JavaSE%E8%BF%9B%E9%98%B6-%E7%BB%A7%E6%89%BF,%E6%8A%BD%E8%B1%A1%E7%B1%BB/#SOHUCS" itemprop="discussionUrl">
      <span id="sourceId::1531b7e9a89083b6ab6209da6b78b583" class="cy_cmt_count" itemprop="commentCount"></span>
    </a>
  </span>
  
  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>866</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>3 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><blockquote class="blockquote-center">
<p>JavaSE进阶——Day01
该篇主要讲解Java中的<strong>继承</strong>、<strong>抽象类</strong></p>

</blockquote>
<span id="more"></span>
<p>学习目标</p>
<ul>
<li><p>面向对象回顾</p></li>
<li><p>面向对象三大特征之一-继承</p>
<ul>
<li><p>继承的格式</p></li>
<li><p>Java继承的特点</p></li>
<li><p>Java继承中成员访问特点</p></li>
</ul></li>
<li><p>抽象类</p>
<ul>
<li><p>抽象类的格式</p></li>
<li><p>抽象类的作用</p></li>
<li><p>抽象类的注意事项</p></li>
</ul></li>
<li><p>设计模式-模板方式</p></li>
</ul>
<h2 id="继承">1继承</h2>
<h3 id="为什么要学习继承">1.1 为什么要学习继承 ?</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>当多个类有相同的属性和行为（非私有成员），为解决代码冗余, 提高代码复用性</span><br><span class="line"><span class="number">2.</span>继承用关键字<span class="string">&#x27;extends&#x27;</span></span><br></pre></td></tr></table></figure>
<h3 id="继承能解决什么问题">1.2 继承能解决什么问题 ?</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>多个类的共有的非私有属性和行为提炼到新的类中,提高代码复用性</span><br><span class="line"><span class="number">2.</span>建立类与类之间的关系(子与父)</span><br><span class="line"><span class="number">3.</span>解决代码冗余</span><br></pre></td></tr></table></figure>
<h3 id="继承中成员访问的特点">1.3 继承中成员访问的特点 ?</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>单一继承（可多层）</span><br><span class="line"><span class="number">2.</span>就近访问（先访问本类成员，找不到再去找父类的）</span><br><span class="line"><span class="number">3.</span>只能访问父类中的非私有成员</span><br><span class="line"><span class="number">4.</span>可使用<span class="string">&#x27;super.成员&#x27;</span>去访问父类成员，<span class="string">&#x27;this.成员&#x27;</span>访问子类成员</span><br></pre></td></tr></table></figure>
<h3 id="方法重写与方法重载区别在于哪里">1.4
方法重写与方法重载区别在于哪里 ?</h3>
<p>方法重载: <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>发生在本类中, 方法名相同, 参数列表不同(类型,数量,顺序)</span><br><span class="line"><span class="number">2.</span>与返回值类型和权限修饰符无关(可相同可不同)</span><br></pre></td></tr></table></figure> 方法重写: <figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>发生在继承关系中(父子类中),当子类与父类的方法一模一样的时候(参数列表和返回值),称为方法重写</span><br><span class="line"><span class="number">2.</span>子类重写的方法权限修饰符 &gt;= 父类的</span><br><span class="line"><span class="number">3.</span>方法重写是为后面的多态做铺垫的</span><br></pre></td></tr></table></figure></p>
<h2 id="抽象类">2. 抽象类</h2>
<h3 id="抽象类存在的意义">2.1 抽象类存在的意义 ?</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>当某个功能较为抽象, 对不类具体实现方式不一样时, 可以使用抽象方法来定义(无具体实现细节), 从而产生了抽象类作为父类</span><br><span class="line"><span class="number">2.</span>使用关键字<span class="string">&#x27;abstract&#x27;</span></span><br><span class="line">Note:</span><br><span class="line"><span class="number">1.</span>抽象类中的抽象方法需要被子类重写</span><br><span class="line"><span class="number">2.</span>抽象类不能够实例化(仅仅是当创建子类对象时, 用来初始化父类)</span><br></pre></td></tr></table></figure>
<h3 id="抽象类使用注意事项">2.2 抽象类使用注意事项 ?</h3>
<h2 id="设计模式难点">3. 设计模式(难点)</h2>
<h3 id="什么是设计模式-设计模式有什么优势">3.1 什么是设计模式 ,
设计模式有什么优势 ?</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">设计模式就是用来解决某个问题的方案</span><br><span class="line">当开发中遇到一些常见问题时候,可以用设计模式实现</span><br></pre></td></tr></table></figure>
<h3 id="模板方法设计模式的作用-使用的方式">3.2 模板方法设计模式的作用 ,
使用的方式 ?</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">规定好某个问题的整体框架和结构</span><br><span class="line">把确定的内容提前写成具体方法, 把不确定的内容写成抽象方法让子类重写</span><br></pre></td></tr></table></figure>
<hr>
<h1 id="笔记">笔记</h1>
<p>面向对象三大特征：</p>
<ol type="1">
<li>封装</li>
<li>继承</li>
<li>多态</li>
</ol>
<p>学习技巧：</p>
<h2 id="继承-1">继承</h2>
<h3 id="问题1什么是继承">问题1：什么是继承</h3>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">继承发生前提：当多个类中有相同的属性和行为时，把这些相同的属性和行为，抽取出来封装一个独立的类中</span><br><span class="line"></span><br><span class="line">在Java中使用继承(extends)，来继承这些封装了公共属性和行为的类（父类）</span><br><span class="line"></span><br><span class="line">继承：有父类、有子类</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">结论：让一个类(子类、派生类)继承另一个类(父类、超类、基类)</span><br></pre></td></tr></table></figure>
<h3 id="问题2继承解决程序中的什么问题">问题2：继承解决程序中的什么问题？</h3>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">1、程序中代码的复用性（重复的代码抽取出来，封装到父类中，子类继承后就可以直接使用）</span><br><span class="line">2、建立类和类之间的关系</span><br></pre></td></tr></table></figure>
<h3 id="问题3继承怎么使用-写代码">问题3：继承怎么使用？ //写代码</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> class 父类&#123;</span><br><span class="line">    <span class="comment">//共性成员</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> class 子类 extends 父类&#123;</span><br><span class="line">    <span class="comment">//子类可以使用父类中定义的内容</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="问题4继承在使用中有使用注意细节">问题4：继承在使用中有使用注意细节</h3>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">1、Java只能单一继承(不能多继承)，允许多层次继承</span><br><span class="line">2、在子类继承父类后，就直接可以父类中非私有的成员（成员变量、成员方法）</span><br><span class="line">3、在继承中，访问成员变量或成员方法的原则：就近原则（先在子类中查找，子类没有再去父类中查找）</span><br><span class="line">    super.父类中的成员变量</span><br><span class="line">    super.父类中的成员方法</span><br><span class="line">4、当父子类中存在一模一样的成员方法时，这种情况称为：方法重写</span><br><span class="line">5、在继承中，要先初始化父类对象（ 通过子类构造方法中的super()来调用父类的无参构造 ）</span><br><span class="line">   //调用父类有参构造方法： super(参数,....);</span><br></pre></td></tr></table></figure>
<h2 id="方法的体现">方法的体现：</h2>
<ol type="1">
<li><h3 id="重载">重载</h3>
<ul>
<li>在本类中发生</li>
<li>方法名相同</li>
<li>方法的参数列表不同（类型不同、数量不同、顺序不同）</li>
<li>和返回值没有任何关系</li>
</ul></li>
<li><h3 id="重写">重写</h3>
<ul>
<li>发生在父子类(继承)中</li>
<li>子类中的方法和父类的方法一模一样</li>
</ul></li>
</ol>
<h2 id="方法重写">方法重写：</h2>
<ol type="1">
<li>什么是方法重写</li>
<li>方法重写解决什么问题</li>
<li>方法重写怎么实现</li>
<li>方法重写有什么注意细节</li>
</ol>
<h2 id="this关键字的使用">this关键字的使用：</h2>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//访问本类中的成员变量</span></span><br><span class="line"><span class="built_in">this</span>.成员变量名=数据值;</span><br><span class="line"></span><br><span class="line"><span class="comment">//访问本类中的成员方法</span></span><br><span class="line"><span class="built_in">this</span>.成员方法();</span><br><span class="line"></span><br><span class="line"><span class="comment">//访问本类中的构造方法（要求：只能使用某个构造方法，去调用本类中另一个构造方法）</span></span><br><span class="line"><span class="keyword">public</span> <span class="title function_">ClassName</span><span class="params">()</span>&#123;</span><br><span class="line">    </span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="title function_">ClassName</span><span class="params">(String name)</span>&#123;</span><br><span class="line">    <span class="built_in">this</span>(); <span class="comment">//调用无参构造方法</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>学习套路：</p>
<ol type="1">
<li>这个技术是什么？</li>
<li>这个技术可以解决什么问题？ （重点）</li>
<li>这个技术怎么使用？ （重点）</li>
<li>这个技术在使用中的注意细节</li>
</ol>
<p>回顾上午内容：</p>
<ul>
<li><p>继承</p>
<ul>
<li><p>继承是什么</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">让一个类继承另一个类</span><br><span class="line">关键字：extends</span><br></pre></td></tr></table></figure></li>
<li><p>继承可以解决什么问题</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">1、建立类与类之间的关系：父子关系</span><br><span class="line">2、可以解决程序中代码的复用性（子类可以直接使用父类中的非私有成员）</span><br></pre></td></tr></table></figure></li>
<li><p>继承怎么使用</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> class 父类&#123;</span><br><span class="line">    <span class="comment">//成员</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> class 子类 extends 父类&#123;</span><br><span class="line">    <span class="comment">//子类可以直接使用父类中的非私有成员</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>继承在使用中的注意细节</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1</span>、Java语言只支持单一继承(不能多继承) ， 允许多层次继承</span><br><span class="line"><span class="number">2</span>、子类不能继承父类中的私有成员</span><br><span class="line"><span class="number">3</span>、当子类和父类中存在相同的成员时，访问原则：就近原则</span><br><span class="line">   <span class="built_in">super</span>.成员变量 </span><br><span class="line">   <span class="built_in">super</span>.成员方法()</span><br><span class="line">   <span class="built_in">super</span>()</span><br><span class="line">   <span class="built_in">super</span>(参数, ...) </span><br><span class="line"><span class="number">4</span>、子类对象在实例化完成之前，必须先初始化父类对象（只有父类初始化完成后子类才可以访问父类成员）</span><br><span class="line">   <span class="comment">//子类构造方法在执行时，有隐藏代码：super()  //默认调用父类中的无参构造方法    </span></span><br></pre></td></tr></table></figure></li>
</ul></li>
<li><p>方法重写</p>
<ul>
<li><p>什么是方法重写</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">当父子类中存在一模一样的非私有成员方法时，就可以称为：子类重写父类的方法（方法重写）</span><br></pre></td></tr></table></figure></li>
<li><p>方法重写可以解决什么问题</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">当父类中的方法，子类在调用时无法满足子类的要求，就可以在子类中重写父类的方法</span><br><span class="line"></span><br><span class="line">目的：</span><br><span class="line">1. 为后面学习多态准备</span><br><span class="line">2. 不愿意在起一个方法名</span><br></pre></td></tr></table></figure></li>
<li><p>方法重写怎么使用</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> class 父类&#123;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">show</span><span class="params">(String name)</span>&#123;</span><br><span class="line">        ....</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> class 子类 extends 父类&#123;</span><br><span class="line">    <span class="comment">//重写方法</span></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">show</span><span class="params">(String name)</span>&#123;</span><br><span class="line">        <span class="comment">//重新编写方法体业务代码</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>方法重写的注意细节</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">1、针对父类中私有方法不能重写</span><br><span class="line">2、必须和父类中的方法一模一样</span><br></pre></td></tr></table></figure></li>
</ul></li>
</ul>
<h2 id="jvm内存划分">JVM内存划分：</h2>
<ol type="1">
<li>栈 //方法运行在栈内存中</li>
<li>堆 //对象存储于堆内存中</li>
<li>方法区 //存放加载的.class文件
//方法区有由N多个不同功能的小区域组成</li>
<li>寄存器<br>
</li>
<li>本地方法区</li>
</ol>
<h3 id="this当前类对象引用">this：当前类对象引用</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">this</span>.成员方法()</span><br><span class="line"><span class="built_in">this</span>.成员变量 = 数据值</span><br><span class="line"><span class="built_in">this</span>() <span class="comment">//本类无参构造方法</span></span><br><span class="line"><span class="built_in">this</span>(<span class="string">&quot;字符串&quot;</span>)<span class="comment">//本类带有String类型参数的构造方法    </span></span><br></pre></td></tr></table></figure>
<h3 id="super父类对象引用">super：父类对象引用</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">super</span>.成员方法()</span><br><span class="line"><span class="built_in">super</span>.成员变量 = 数据值</span><br><span class="line"><span class="built_in">super</span>() <span class="comment">//父类无参构造方法</span></span><br><span class="line"><span class="built_in">super</span>(<span class="string">&quot;字符串&quot;</span>)<span class="comment">//父类带有String类型参数的构造方法   </span></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//父类：动物类</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">class</span> <span class="title class_">Animal</span>&#123;</span><br><span class="line">    <span class="comment">//抽象方法：必须使用关键字abstract修饰</span></span><br><span class="line">    <span class="comment">//抽象方法：必须书写在抽象类中</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> <span class="title function_">eat</span><span class="params">()</span>;<span class="comment">//在java语言中没有方法体的方法，称为：抽象方法 </span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="普通类">普通类:</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> class 类名&#123;</span><br><span class="line">    <span class="comment">//成员变量</span></span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//成员方法</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setName</span><span class="params">(String name)</span>&#123;</span><br><span class="line">        <span class="built_in">this</span>.name = name;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//构造方法</span></span><br><span class="line">    <span class="keyword">public</span> 类名&#123;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="抽象类-1">抽象类：</h3>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> class 类名&#123;</span><br><span class="line">    <span class="comment">//成员变量</span></span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//成员方法</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">setName</span><span class="params">(String name)</span>&#123;</span><br><span class="line">        <span class="built_in">this</span>.name = name;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//构造方法</span></span><br><span class="line">    <span class="keyword">public</span> 类名&#123;</span><br><span class="line">        </span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">//抽象方法</span></span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">abstract</span> <span class="keyword">void</span> 抽象方法();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ul>
<li>抽象类，不能实例化（不能创建对象）
<ul>
<li>疑问：既然不能创建对象了，为什么还要有构造方法？
<ul>
<li>抽象类通常是用于父类，创建子类对象时，需要先初始化父类（抽象方法中构造方法的作用就是用于父类初始化使用）</li>
</ul></li>
</ul></li>
<li>抽象类中的抽象方法，必须由子类重写</li>
</ul>
<h2 id="什么是设计模式">什么是设计模式？</h2>
<ul>
<li>设计模式，就是一种解决方案（解决开发中某个问题的方案）</li>
</ul>
<p>设计模式解决什么问题？</p>
<ul>
<li>在开发中一些常见问题，可以使用设计模式解决</li>
</ul>
<h3 id="模板设计模式">模板设计模式：</h3>
<ul>
<li>模板：就一个固定的格式</li>
<li>模板设计：把确定的内容，提前准备好，把不确定的内容，定义为抽象方法（由子类重写）</li>
</ul>
<p>创建对象：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">Student</span> <span class="variable">stu</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">Student</span>(); <span class="comment">//有名字的对象</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//对象名： stu</span></span><br></pre></td></tr></table></figure>
<p>匿名对象：</p>
<ul>
<li>没有名字的对象</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">new</span> <span class="title class_">Student</span>(); <span class="comment">//创建的对象没有名字</span></span><br><span class="line"><span class="keyword">new</span> <span class="title class_">Student</span>(<span class="string">&quot;张三&quot;</span>,<span class="number">23</span>);</span><br></pre></td></tr></table></figure>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="reward-container">
  <div>请我一杯咖啡吧！</div>
  <button>
    赞赏
  </button>
  <div class="post-reward">
      <div>
        <img src="/images/wChat.png" alt="Ethan Liu 微信">
        <span>微信</span>
      </div>

  </div>
</div>

          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>Ethan Liu
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="http://ethanliu6.github.io/2024/03/25/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day01/day01_JavaSE%E8%BF%9B%E9%98%B6-%E7%BB%A7%E6%89%BF,%E6%8A%BD%E8%B1%A1%E7%B1%BB/" title="JavaSE进阶——Day01 继承、抽象类">http://ethanliu6.github.io/2024/03/25/JavaNotes/JavaSE进阶/day01/day01_JavaSE进阶-继承,抽象类/</a>
  </li>
  <li class="post-copyright-license">
      <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC8="><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


          <div class="post-tags">
              <a href="/tags/Java/" rel="tag"><i class="fa fa-tag"></i> Java</a>
              <a href="/tags/Java%E8%BF%9B%E9%98%B6/" rel="tag"><i class="fa fa-tag"></i> Java进阶</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2024/03/24/JavaNotes/JavaSE%E5%9F%BA%E7%A1%80/day09%E5%8A%A8%E6%BC%AB%E7%BE%8E%E5%A5%B3%E6%8B%BC%E5%9B%BE/" rel="prev" title="JavaSE基础——Day09 JavaSE基础——综合案例动漫美女拼图">
                  <i class="fa fa-angle-left"></i> JavaSE基础——Day09 JavaSE基础——综合案例动漫美女拼图
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2024/04/01/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day02/day02_JavaSE%E8%BF%9B%E9%98%B6-%E4%BB%A3%E7%A0%81%E5%9D%97,%E6%8E%A5%E5%8F%A3,%E6%9E%9A%E4%B8%BE/" rel="next" title="JavaSE进阶——Day02 代码块、接口、枚举">
                  JavaSE进阶——Day02 代码块、接口、枚举 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments" id="SOHUCS" sid="1531b7e9a89083b6ab6209da6b78b583"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2023-2024 – 
    <span itemprop="copyrightYear">2024</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">Is Ethan's</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">113k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">6:51</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>

    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

  <span class="exturl github-corner" data-url="aHR0cHM6Ly9naXRodWIuY29tL0V0aGFuTGl1Ni8=" title="在 GitHub 上关注我" aria-label="在 GitHub 上关注我"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></span>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.33/fancybox/fancybox.umd.js" integrity="sha256-+2+qOqR8CKoHh/AsVR9k2qaDBKWjYNC2nozhYmv5j9k=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/medium-zoom/1.1.0/medium-zoom.min.js" integrity="sha256-ZgMyDAIYDYGxbcpJcfUnYwNevG/xi9OHKaR/8GK+jWc=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>

  <script class="next-config" data-name="pdf" type="application/json">{"object_url":{"url":"https://cdnjs.cloudflare.com/ajax/libs/pdfobject/2.2.12/pdfobject.min.js","integrity":"sha256-g2xji1rlE3KsGVClvuxTbcR0Kn2+wtQADSff2Tbb4zA="},"url":"/lib/pdf/web/viewer.html"}</script>
  <script src="/js/third-party/tags/pdf.js"></script>



  <script src="/js/third-party/fancybox.js"></script>



  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"all","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


  <script src="https://cdnjs.cloudflare.com/ajax/libs/quicklink/2.3.0/quicklink.umd.js" integrity="sha256-yvJQOINiH9fWemHn0vCA5lsHWJaHs6/ZmO+1Ft04SvM=" crossorigin="anonymous"></script>
  <script class="next-config" data-name="quicklink" type="application/json">{"enable":true,"home":true,"archive":true,"delay":true,"timeout":3000,"priority":true,"url":"http://ethanliu6.github.io/2024/03/25/JavaNotes/JavaSE%E8%BF%9B%E9%98%B6/day01/day01_JavaSE%E8%BF%9B%E9%98%B6-%E7%BB%A7%E6%89%BF,%E6%8A%BD%E8%B1%A1%E7%B1%BB/"}</script>
  <script src="/js/third-party/quicklink.js"></script>
<script class="next-config" data-name="changyan" type="application/json">{"enable":true,"appid":"cyxf6tytI","appkey":"90987f30c4b5248baad5a04c7a6abfe1","count":true}</script>
<script src="/js/third-party/comments/changyan.js"></script>

</body>
</html>
